package controller;

import com.opensymphony.xwork2.ActionSupport;

import dao.VisitorDAO;

import entity.Visitor;

public class RegisterAction extends ActionSupport{
	private String username;
	private String password;
	private String repassword;
	private String firstname;
	private String lastname;
	private String email;
	private String gender;
	private String telephone;
	private String [] hobbies;
	private String area;
	private String description;
	
	public String execute(){				
		Visitor vb=new Visitor();
		String hobbiess = "";
		
		for (String s : hobbies) {
			hobbiess += s + ",";
		}
		
		vb.setUserName(username);
		// Ma hoa password theo thuat toan MD5
		vb.setPassword(EncyptPassword.encryptMD5(password));
		System.out.println(" Register Action say: "+ EncyptPassword.encryptMD5(password));
		vb.setFirstName(firstname);
		vb.setLastName(lastname);
		vb.setGender(gender);
		vb.setArea(area);
		vb.setEmail(email);
		vb.setTelephone(telephone);
		vb.setHobby(hobbiess);
		vb.setDescription(description);		
		
		if(VisitorDAO.addVisitor(vb)) {
			return SUCCESS;
		} else {
			addActionError("Can not add visitor, try again!");
			return ERROR;
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String[] getHobbies() {
		return hobbies;
	}

	public void setHobbies(String[] hobbies) {
		this.hobbies = hobbies;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}
